-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#321 search page bug #322
#321 search page bug #322
Conversation
FrontEnd/src/hooks/useProvideAuth.js
Outdated
); | ||
) | ||
.then((res) => res.data); | ||
setUserId(userData.id); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use existing useUser hook instead of adding userData here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think, we need additional request to api/users/me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useUser hook provides all the information about authorized user. And you can access this data when you need it.
It is common practice to use this hook. And it's no need to duplicate the logic of getting user id.
And we get that information via request to api/users/me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I as authorized user put smth to the searchpage and press enter iuseProvideAuth sends the request to api/users/me. So I use it. If I'll use useUser it will send this request again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have duplicated logic in our code)
I'd recommend to wait for Oleg review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change code, but I'm not sure in this solution. We are waiting for Oleg))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have useUser hook. My proposition is to use it instead of adding userData in useProvideAuth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Lvyshnevska , inside a useUser
hook we utilize a useSWR
which should cache fetched data and prevent second API call. There is no need to call /api/auth/users/me/
the second time if it was already called and cached in the useUser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Done. But both hooks useUser and useProvideAuth use the same request /api/auth/users/me/ to the backend. Is it ok? I mean if I can use only useUser to check authenticated user or not and to get his data (id for my case), why do we need useProvideAuth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as what I see we return different values from these hooks. But since they use the same API I assume that we can combine them both into one hook. Also, we do not use SWR in useProvideAuth
that's something that could be fixed
Approved, but would be happy to resolve tech debt between |
I found some problems on our site.
I rebuild our site from this branch, so you can see my changes "in nature"